/*
 * @Author: C.
 * @Date: 2023-03-27 10:20:13
 */
import { apiMaps, ApiNames } from '../../maps/apis/index';
import { defHttp } from '/@/utils/http/axios';
import { useLoading } from '/@/components/Loading';
const [openFullLoading, closeFullLoading] = useLoading({});
// import {  } from "/@/components/Loading/src/createLoading";
export type IReName = {
  [x in `api_${ApiNames}`]: Fn;
};
export function createApiModule(moduleName: string): IReName {
  const apiModule = {};
  for (const key in apiMaps) {
    const obj = apiMaps[key];
    const apiName = 'api_' + obj.value;
    apiModule[apiName] = async function (params) {
      let res;
      try {
        obj.loading && openFullLoading();
        res = await defHttp[obj.method]({
          url: `/${moduleName}/${obj.value}`,
          params,
        });
        obj.loading && closeFullLoading();
      } catch (error) {
        obj.loading && closeFullLoading();
      }

      return res;
    };
  }
  return apiModule as IReName;
}
